package cn.flkj.welucia;

import com.webank.wecrosssdk.exception.WeCrossSDKException;
import com.webank.wecrosssdk.resource.Resource;
import com.webank.wecrosssdk.resource.ResourceFactory;
import com.webank.wecrosssdk.rpc.WeCrossRPC;
import com.webank.wecrosssdk.rpc.WeCrossRPCFactory;
import com.webank.wecrosssdk.rpc.service.WeCrossRPCService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author : 州长在手 2020/11/16 上午11:24
 */
@Component
public class Runner implements CommandLineRunner {


    @Override
    public void run(String... args) {
        System.out.println(">>>>>>>>>>>>>>>服务启动执行，执行加载数据等操作<<<<<<<<<<<<<");

        try {
            // 初始化 Service
            WeCrossRPCService weCrossRPCService = new WeCrossRPCService();

            // 初始化Resource
            WeCrossRPC weCrossRPC = WeCrossRPCFactory.build(weCrossRPCService);
            // payment.bcos.HelloWecross
            Resource resource = ResourceFactory.build(weCrossRPC, "fuchain.fabric.sacc", "Admin"); // RPC服务，资源的path，用哪个账户名操作此resource

            // 用初始化好的resource进行调用
            String[] callRet = resource.call("get" ,"a");   // call 接口函数名 参数列表
            System.out.println((Arrays.toString(callRet)));

            // 用初始化好的resource进行调用
           // String[] sendTransactionRet = resource.sendTransaction("set", "Tom"); // sendTransaction 接口函数名 参数列表
          //  System.out.println((Arrays.toString(sendTransactionRet)));

        } catch (  WeCrossSDKException e) {
            System.out.println("Error: " + e);
        }

    }
}
